package Test;

public class 二叉树的最大路径和1 {
    int res=Integer.MIN_VALUE;
    public int maxPathSum(TreeNode root) {
        if(root==null) return 0;
        oneside(root);
        return res;
    }

    int oneside(TreeNode root){
        if(root==null) return 0;
        int left=Math.max(0,oneside(root.left));
        int right=Math.max(0,oneside(root.right));
        res=Math.max(res,left+right+ root.val);
        return Math.max(left,right)+ root.val;
    }

}
